package com.hfi.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author ChangLiang
 * @date 2019/5/16
 */
public class UserSaveHandler implements InvocationHandler {

    private Object target;

    public UserSaveHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Object result = null;
        String methodName = method.getName();
        if ("save".equals(methodName)) {
            System.out.println("before user save action");
            result = method.invoke(target, args);
            System.out.println("after user save action");
        } else {
            result = method.invoke(target, args);
        }
        return result;
    }
}
